﻿
namespace ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer.Engine.Modules.LowLevel.Midi
{
    [ModuleDisplay("Midi Octave Mod")]
    class MidiOctaveModModule : BaseModule
    {
        private const int NOTES = 12;

        public readonly ModuleInput MidiIn;
        public readonly ModuleOutput[] MidiNoteOuts;

        public MidiOctaveModModule(ModuleManager manager)
            : base(manager)
        {
            AddInput(MidiIn = new ModuleInput("In", IOType.Midi, this));
            MidiNoteOuts = new ModuleOutput[NOTES];
            for (int i = 0; i < NOTES; i++)
            {
                MidiNoteOuts[i] = new ModuleOutput("Out N" + (i + 1), IOType.Midi, this);
                AddOutput(MidiNoteOuts[i]);
            }
        }

        public override void Process()
        {
            if (MidiIn.IsConnected)
            {
                foreach (var midi in MidiIn.FromOutput.MidiBuffer)
                {
                    int note = midi.MidiData.Parameter1 & NOTES;
                    MidiNoteOuts[note].AddMidiMessage(midi);
                }
            }
        }
    }
}
